﻿#include "btform.h"
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);

    ui->lineBox->hide();

    line1Animal = new QPropertyAnimation(ui->line1, "geometry", this);
    line1Animal->setDuration(1500);//设置持续时长
    line1Animal->setKeyValueAt(0, QRect(0, 25, 2, 0));
    line1Animal->setKeyValueAt(0.5, QRect(0, 0, 2, 25));
    line1Animal->setKeyValueAt(1, QRect(0, 25, 2, 0));
    line1Animal->setLoopCount(-1);//设置循环次数,-1是无限循环
    line1Animal->start();

    line2Animal = new QPropertyAnimation(ui->line2, "geometry", this);
    line2Animal->setDuration(1600);//设置持续时长
    line2Animal->setKeyValueAt(0, QRect(7, 25, 2, 0));
    line2Animal->setKeyValueAt(0.5, QRect(7, 0, 2, 25));
    line2Animal->setKeyValueAt(1, QRect(7, 25, 2, 0));
    line2Animal->setLoopCount(-1);//设置循环次数,-1是无限循环
    line2Animal->start();

    line3Animal = new QPropertyAnimation(ui->line3, "geometry", this);
    line3Animal->setDuration(1700);//设置持续时长
    line3Animal->setKeyValueAt(0, QRect(14, 25, 2, 0));
    line3Animal->setKeyValueAt(0.5, QRect(14, 0, 2, 25));
    line3Animal->setKeyValueAt(1, QRect(14, 25, 2, 0));
    line3Animal->setLoopCount(-1);//设置循环次数,-1是无限循环
    line3Animal->start();

    line4Animal = new QPropertyAnimation(ui->line4, "geometry", this);
    line4Animal->setDuration(1800);//设置持续时长
    line4Animal->setKeyValueAt(0, QRect(21, 25, 2, 0));
    line4Animal->setKeyValueAt(0.5, QRect(21, 0, 2, 25));
    line4Animal->setKeyValueAt(1, QRect(21, 25, 2, 0));
    line4Animal->setLoopCount(-1);//设置循环次数,-1是无限循环
    line4Animal->start();
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::showAnimal() {
    ui->lineBox->show();
}

void BtForm::setIconAndText(const QString& btIcon, const QString& btText, int pageId) {
    //设置图标
    ui->btIcon->setPixmap(btIcon);

    //设置文本
    ui->btText->setText(btText);

    pageId_ = pageId;
}

void BtForm::mousePressEvent(QMouseEvent* event) {
    ui->btStyle->setStyleSheet("#btStyle{background-color:rgb(30, 206, 154);}");

    //将按钮和页面进行关联
    emit btClick(pageId_);
}

int BtForm::getpageId() const {
    return pageId_;
}

void BtForm::closeBackground() {
    ui->btStyle->setStyleSheet("#btStyle:hover{background:#D8D8D8;}");
}
